<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
   <link rel="stylesheet" href="__PUBLIC__/Css/Admin/common.css">
   <link rel="stylesheet" href="__PUBLIC__/Css/Admin/main.css">
   <style type="text/css">
	  .editor{
		  width:60%;
	  	  height:300px;
  		  margin-bottom:50px;
	  }
   </style>
   
   <script type="text/javascript" src="__PUBLIC__/Js/Admin/jquery.min.js"></script>
   <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
   <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"> </script>
   <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
   <title>编辑景点</title>
   
   <script type="text/javascript">
       $(function(){
    	   
	    	// 初始化编辑器
	       	$(".editor").each(function(){
	       		UE.getEditor($(this).get(0).id);
	       	});
    	
    	   // 提交前check
    	   checkBeforeSubmit();
    	   
    	  // 推荐check景点最多只能推荐4个
    	   $("#recommend").click(function(){
    		   var city = $("select[name='city'] :selected").val();
        	   if($.trim(city) == "" || city == 0){
        		   alert("请先选择城市");
        		   return false;
        	   }
    		   if($(this).is(":checked")){
    			   $.ajax({
 	    			  url:"__URL__/checkRecommend",
 	    			  type:"POST",
 					  async: true,
 					  data: "type=1&city=" + city,
 					  dataType: "text",
 					  success:function(respData) {
 						   if(respData == "false"){
 							   alert("最多只能推荐4个景点！");
 							  $("#unrecommend").prop("checked", "true");
 						   } else if(respData == ""){
 							  alert("推荐检查失败，请重新设定!");
 							  $("#unrecommend").prop("checked", "true");
 						   }
 					  },
 					  error:function(){
 						 alert("推荐检查失败，请重新设定!");
 						 $("#unrecommend").prop("checked", "true");
 					  }
 	    		   });
    		   }
    	   });
    	   
       });
       
       // 提交前check
       function checkBeforeSubmit(){
    	   $("#save_button").click(function(){
    		   // 景点ID
    		   var attractionId = $("input[name='attractionId']").val();
    		   // 景点名称
    		   var name = $("input[name='name']").val();
    		   // 图片
    		   var imgUrl1 = $("input[name='file1']").val();
    		   var imgUrl2 = $("input[name='file2']").val();
    		   var imgUrl3 = $("input[name='file3']").val();
    		   var imgUrl4 = $("input[name='file4']").val();
    		   var imgUrl5 = $("input[name='file5']").val();
    		   var imgUrl6 = $("input[name='file6']").val();
    		   var imgUrl7 = $("input[name='file7']").val();
    		   // 联系电话
    		   var telePhone = $("input[name='tele_phone']").val();
    		   // email
    		   var email = $("input[name='email']").val();
    		   // 地址
    		   var address = $("input[name='address']").val();
    		   // 简介
    		   var detail = $("textarea[name='detail']").val();
    		   
    		   // 输入check 
    		   if($.trim(name) == ""){
    			   alert("请输入景点名称！");
    			   return false;
    		   }
    		   // 新增是check图片
    		   if($.trim(attractionId) == ""){
    			   if($.trim(imgUrl1) == "" || $.trim(imgUrl2) == ""
    				   || $.trim(imgUrl3) == "" || $.trim(imgUrl4) == ""
   					   || $.trim(imgUrl4) == "" || $.trim(imgUrl5) == ""
					   || $.trim(imgUrl6) == "" || $.trim(imgUrl7) == ""){
        			   alert("请选择景点图片！");
        			   return false;
        		   }
    		   }
    		   if($.trim(telePhone) == ""){
    			   alert("请输入联系电话！");
    			   return false;
    		   }
    		   // 电子邮箱check
    		   if(!$.trim(email) == ""){
    			   
    		   }
    		   if($.trim(address) == ""){
    			   alert("请输入景点地址！");
    			   return false;
    		   }
    		   if($.trim(detail) == ""){
    			   alert("请输入景点介绍！");
    			   return false;
    		   }
    		   if(UE.getEditor("feature").hasContents() == false){
	   			   alert("请填写景点特色！");
	   			   return false;
       			}
    		   if(UE.getEditor("order_note").hasContents() == false){
	   			   alert("请填写预订须知！");
	   			   return false;
       			}
    		   if(UE.getEditor("cost_explain").hasContents() == false){
	   			   alert("请填写费用说明！");
	   			   return false;
       			}
    		   
    		   var typeId = $("select[name='type'] :selected").val();
    		   var cityId = $("select[name='city'] :selected").val();
    		   if($.trim(attractionId) == ""){
    			   $.ajax({
    	    			  url:"__URL__/hasAttrName",
    	    			  type:"POST",
    					  async: false,
    					  data: "id=" + attractionId + "&name=" + $.trim(name) +"&typeId=" + typeId + "&cityId" + cityId,
    					  dataType: "text",
    					  success:function(respData) {
    						   if(respData == "false"){
    							   alert("当前名称的景点已经存在，请输入其他名称！");
    						   } else if(respData == "true"){
    							   $("#attraction_form").submit(); 
    						   }
    					  },
    					  error:function(){
    					    	
    					  }
    	    		   });
    		   } else {
    			   $("#attraction_form").submit(); 
    		   }
    	   });
       }
   </script>
</head>
<body>
<div id="forms" class="mt10">
       <div class="box">
          <div class="box_border">
            <div class="box_top">
            	<b class="pl15">{$title}</b>
            	<a class="ext_btn" onclick="location.href='javascript:history.go(-1)'" style="float:right;margin-right:10px;margin-top:5px;">返回</a>
            </div>
            <div class="box_center">
              <form action="{:U('Attraction/saveAttr')}" class="jqtransform" id="attraction_form" method="post" enctype="multipart/form-data">
                <input type="hidden" name="attractionId" value="{$attraction.id}">
               <table class="form_table pt15 pb15" style="width:100%">
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点名称：</td>
                  <td class=""> 
                    <input type="text" name="name" class="input-text lh30" size="40" value="{$attraction.name}">
                  </td>
                </tr>
                 <tr >
                  <td class="td_right"><label style="color:red;">*</label>景点类型：</td>
                  <td class="">
                      <div class="select_border"> 
                        <div class="select_containers "> 
                        <select name="type" class="select"> 
                        	<foreach name="typeList" item="type">
                        		<if condition="$type.id eq ($attraction['attraction_type_id'])">
                        			<option value="{$type.id}" selected>{$type.name}</option>
                        		<else />
                        			<option value="{$type.id}">{$type.name}</option>
                        		</if>
                        	</foreach> 
                        </select> 
                        </div> 
                      </div> 
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right"><label style="color:red;">*</label>所在城市：</td>
                  <td class="">
                      <div class="select_border"> 
                        <div class="select_containers "> 
                        <select name="city" class="select"> 
                        	<foreach name="cityList" item="city">
                        		<if condition="$city.id eq ($attraction['city_id'])">
                        			<option value="{$city.id}" selected>{$city.name}</option>
                        		<else />
                        			<option value="{$city.id}">{$city.name}</option>
                        		</if>
                        	</foreach> 
                        </select> 
                        </div> 
                      </div> 
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right"><label style="color:red;">*</label>价格：</td>
                  <td class=""> 
                    <input type="text" name="price" class="input-text lh30" size="10" value="{$attraction.price}">元
                  </td>
                 </tr>
                 
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片1：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file1" class="input-text lh30" size="10">
                  	<if condition="$attraction.first_img_path neq null">
                  	<img id="selected_img_1" src="__PUBLIC__/Uploads/{$attraction.first_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片2：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file2" class="input-text lh30" size="10">
                  	<if condition="$attraction.second_img_path neq null">
                  	<img id="selected_img_2" src="__PUBLIC__/Uploads/{$attraction.second_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片3：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file3" class="input-text lh30" size="10">
                  	<if condition="$attraction.third_img_path neq null">
                  	<img id="selected_img_3" src="__PUBLIC__/Uploads/{$attraction.third_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片4：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file4" class="input-text lh30" size="10">
                  	<if condition="$attraction.forth_img_path neq null">
                  	<img id="selected_img_4" src="__PUBLIC__/Uploads/{$attraction.forth_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片5：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file5" class="input-text lh30" size="10">
                  	<if condition="$attraction.fifth_img_path neq null">
                  	<img id="selected_img_5" src="__PUBLIC__/Uploads/{$attraction.fifth_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片6：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file6" class="input-text lh30" size="10">
                  	<if condition="$attraction.sixth_img_path neq null">
                  	<img id="selected_img_6" src="__PUBLIC__/Uploads/{$attraction.sixth_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点图片7：</td>
                  <td class="">
                  	<!-- <input type="button" class="ext_btn" id="select_img_btn" value="选择..."> -->
                  	<input type="file" name="file7" class="input-text lh30" size="10">
                  	<if condition="$attraction.seventh_img_path neq null">
                  	<img id="selected_img_7" src="__PUBLIC__/Uploads/{$attraction.seventh_img_path}" style="border:1px solid black;height:80px; width:80px;">
                  	</if>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>联系电话：</td>
                  <td class=""> 
                    <input type="text" name="tele_phone" class="input-text lh30" size="40" value="{$attraction.tele_phone}">
                  </td>
                </tr>
                <tr>
                  <td class="td_right">电子邮箱：</td>
                  <td class=""> 
                    <input type="text" name="email" class="input-text lh30" size="40" value="{$attraction.email}">
                  </td>
                </tr>
                <tr>
                  <td class="td_right"><label style="color:red;">*</label>地址：</td>
                  <td class=""> 
                    <input type="text" name="address" class="input-text lh30" size="40" value="{$attraction.address}">
                  </td>
                </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>景点介绍：</td>
                  <td class="">
                    <textarea name="detail" id="" cols="30" rows="10" class="textarea">{$attraction.detail}</textarea>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>是否推荐：</td>
                  <td class="">
                  	<if condition="$attraction.is_recommend eq 1">
	                    <input type="radio" name="is_recommend" id="recommend" value="1" checked> 推荐
	                    <input type="radio" name="is_recommend" id="unrecommend" value="0" > 不推荐
                    <else />
	                    <input type="radio" name="is_recommend" id="recommend" value="1" > 推荐
	                    <input type="radio" name="is_recommend" id="unrecommend" value="0" checked> 不推荐
                    </if>
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right" style="vertical-align:top;">优惠活动：</td>
                  <td class="">
                      <script id="discount" class="editor" type="text/plain" name="discount">
					  		{$attraction.discount}
					  </script> 
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right" style="vertical-align:top;"><label style="color:red;">*</label>景点特色：</td>
                  <td class="">
                      <script id="feature" class="editor" type="text/plain" name="feature">
					  		{$attraction.feature}
					  </script> 
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right" style="vertical-align:top;"><label style="color:red;">*</label>预订须知：</td>
                  <td class="">
                      <script id="order_note" class="editor" type="text/plain" name="order_note">
					  		{$attraction.order_note}
					  </script> 
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right" style="vertical-align:top;"><label style="color:red;">*</label>费用说明：</td>
                  <td class="">
                      <script id="cost_explain" class="editor" type="text/plain" name="cost_explain">
					  		{$attraction.cost_explain}
					  </script> 
                  </td>
                 </tr>
                 <tr >
                  <td class="td_right" style="vertical-align:top;">相关产品：</td>
                  <td class="">
                      <script id="releated_product" class="editor" type="text/plain" name="releated_product">
					  		{$attraction.releated_product}
					  </script> 
                  </td>
                 </tr>
                 <tr>
                   <td class="td_right">&nbsp;</td>
                   <td class="">
                     <input type="button" name="save_button" id="save_button" class="btn btn82 btn_save2" value="保存"> 
                    <input type="reset" name="reset_button" class="btn btn82 btn_res" value="重置">
                   </td>
                 </tr>
               </table>
               </form>
            </div>
          </div>
        </div>
     </div>
</body>
</html>